locals {
  dcs_redis_groups = {
    myapp = {
      redis_name    = "dcs-myapp-dev"
      redis_version = "4.0"
      capacity      = 4
      redis_flavor  = "redis.proxy.xu1.large.4"
      ava_zone      = ["${var.REGION}a", "${var.REGION}b"]
      vpc_id        = data.terraform_remote_state.vpc.outputs.vpc_info.id
      subnet_id     = data.terraform_remote_state.subnet.outputs.subnet_info["subnet-me212-dev-baidu_hub-db-redis"].id
      vsg_id        = data.terraform_remote_state.vsg.outputs.vsg_info.vsg_mysql.vsg_id
      password      = var.pwd_redis_myapp
      whitelists_ip = data.terraform_remote_state.vpc.outputs.vpc_info.cidr
    }
    miniapp = {
      redis_name    = "dcs-miniapp-dev"
      redis_version = "4.0"
      capacity      = 4
      redis_flavor  = "redis.proxy.xu1.large.4"
      ava_zone      = ["${var.REGION}a", "${var.REGION}b"]
      vpc_id        = data.terraform_remote_state.vpc.outputs.vpc_info.id
      subnet_id     = data.terraform_remote_state.subnet.outputs.subnet_info["subnet-me212-dev-baidu_hub-db-redis"].id
      vsg_id        = data.terraform_remote_state.vsg.outputs.vsg_info.vsg_mysql.vsg_id
      password      = var.pwd_redis_miniapp
      whitelists_ip = data.terraform_remote_state.vpc.outputs.vpc_info.cidr
    }
  }
}

module "dcs" {
  source             = "../../../modules/dcs"
  for_each           = local.dcs_redis_groups
  redis_name         = each.value.redis_name
  redis_version      = each.value.redis_version
  capacity           = each.value.capacity
  redis_flavor       = each.value.redis_flavor
  availability_zones = each.value.ava_zone
  password           = each.value.password
  vpc_id             = each.value.vpc_id
  subnet_id          = each.value.subnet_id
  whitelists_ip      = [each.value.whitelists_ip]
}
